package net.cloudsun.graph.puzzle;

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import net.cloudsun.graph.util.ArrayUtils;

/**
 * 图形化的
 *
 * @author Ryan
 * @since 1.0
 */
public class JigsawStateImage {
    // 静态8个图片对象
    private static Image[] IMAGE_POOL = new Image[9];
    static {
        int index = 0;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                IMAGE_POOL[index++] = new Image("file://images/" + i + "-" + j + ".png");
            }
        }
    }
    private JigsawState jigsawState;

    public JigsawStateImage(JigsawState jigsawState) {
        this.jigsawState = jigsawState;
    }

    public ImageView[] toImage() {
        final int[] ints = ArrayUtils.joinArray(jigsawState.toArray());
        final ImageView[] images = new ImageView[ints.length];
        for (int i = 0; i < ints.length; i++) {
            images[i] = new ImageView(IMAGE_POOL[ints[i]]);
        }
        return images;
    }
}
